﻿using Alimentador.CustomControls;
using Alimentador.Foods;
using Alimentador.RightGroup.Patient;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Alimentador.Patient
{
    /// <summary>
    /// Interaction logic for PatientCtrl.xaml
    /// </summary>
    public partial class PatientCtrl : UserControl
    {
        public delegate void LoadDataEventDelegate(bool loaded);
        public event LoadDataEventDelegate LoadDataEvent;

        /// <summary>
        /// "criada a "
        /// </summary>
        private const string CREATION_DATE_TEXT = "criada a ";

        private string m_CurrentPersonFile = "";

        private bool m_hasChanges = false;
        private bool m_hasError = false;

        private int m_maxYear = 0;


        /// <summary>
        /// Constructor
        /// </summary>
        public PatientCtrl()
        {
            InitializeComponent();
            InitializeEvents();
            InitiValues();
        }

        /// <summary>
        /// Add all component events
        /// </summary>
        private void InitializeEvents()
        {
            NameTxtBox.TextChanged += NameTxtBox_TextChanged;

            YOBCBox.SelectionChanged += YOBCBox_SelectionChanged;

            MaleRBtn.Checked += MaleRBtn_CheckedChanged;
            MaleRBtn.Unchecked += MaleRBtn_CheckedChanged;

            FemaleRBtn.Checked += FemaleRBtn_CheckedChange;
            FemaleRBtn.Unchecked += FemaleRBtn_CheckedChange;

            PregantRBtn.Checked += PregantRBtn_CheckedChanged;
            PregantRBtn.Unchecked += PregantRBtn_CheckedChanged;

            FeedingRBtn.Checked += FeedingRBtn_CheckedChanged;
            FeedingRBtn.Unchecked += FeedingRBtn_CheckedChanged;

            WaistTxtBox.TextChanged += WaistTxtBox_TextChanged;
            WaistTxtBox.LostFocus += WaistTxtBox_LostFocus;

            WeightTxtBox.TextChanged += WeightTxtBox_TextChanged;
            HeightTxtBox.TextChanged += HeightTxtBox_TextChanged;

            ObsTxtBox.TextChanged += ObsTxtBox_TextChanged;
        }

        /// <summary>
        /// Set components initial values
        /// </summary>
        private void InitiValues()
        {
            m_CurrentPersonFile = "";
            CreationDateLbl.Content = "";

            ObsTxtBox.Text = "";

            HasChanges = false;

            TopGrid.IsEnabled =
                EvolutionBtn.IsEnabled =
                SaveBtn.IsEnabled =
                EditBtn.IsEnabled =
                DeleteBtn.IsEnabled = false;

            MaleRBtn.IsChecked = true;

            PregantRBtn.IsEnabled =
                FeedingRBtn.IsEnabled = (bool)FemaleRBtn.IsChecked;

            NameTxtBox.Text =
                YOBCBox.Text =
                IMCTxtBox.Text =
                HeightTxtBox.Text =
                WeightTxtBox.Text =
                WaistTxtBox.Text = "";

            if (YOBCBox.Items.Count == 0)
            {
                DateTime dt = DateTime.Now;
                m_maxYear = dt.Year - PersonPatient.MINIMUM_AGE;
                //ComboBoxItem cbItem = new ComboBoxItem();
                //cbItem.Name = "cbItem0";
                //cbItem.Content = "(Ano)";
                //YOBCBox.Items.Add(cbItem);
                //cbItem.IsSelected = true;
                //YOBCBox.SelectedIndex = 0;

                int minDiff = m_maxYear - 1900;

                for (int i = minDiff; i > 0; i--)
                {
                    ComboBoxItem cbItem = new ComboBoxItem();
                    cbItem.Name = "cbItem" + (1900 + i).ToString();
                    cbItem.Content = (1900 + i).ToString();
                    YOBCBox.Items.Add(cbItem);
                    if (i == minDiff)
                    {
                        cbItem.IsSelected = true;
                        // YOBCBox.SelectedIndex = i;
                    }
                }
            }
            RatingStarValues.SetStarValues(DefaultValues.PatStarRatingValues.ActivityNone);
        }

        /// <summary>
        /// Set if something has changed. Enables SaveBtn.
        /// </summary>
        public bool HasChanges
        {
            private set
            {
                m_hasChanges = value;
                if (value)
                {
                    DoCalculations();
                    SaveBtn.IsEnabled = true;
                }

                if (MainWindow.CurrentPatient != null && !string.IsNullOrEmpty(MainWindow.CurrentPatient.PatName))
                {
                    if (LoadDataEvent != null)
                    {
                        LoadDataEvent(true);
                    }
                }
            }
            get
            {
                return m_hasChanges;
            }
        }

        /// <summary>
        /// Set if there is an error on values. Disables SaveBtn.
        /// </summary>
        private bool HasError()
        {
            PersonPatient p = MainWindow.CurrentPatient;
            m_hasError = false;

            if (string.IsNullOrEmpty(NameTxtBox.Text))
            {
                NameTxtBox.BorderBrush = Brushes.Red;
                m_hasError = true;
            }

            if (FoodFormulas.CalculateAge(p.PatBirthYear) == 0)
            {
                YOBCBox.Foreground = Brushes.Red;
                m_hasError = true;
            }

            if (p.PatHeight < MainWindow.Def.MINIMUM_HEIGHT)
            {
                HeightTxtBox.BorderBrush = Brushes.Red;
                m_hasError = true;
            }

            if (p.PatWeight < MainWindow.Def.MINIMUM_WEIGTH)
            {
                WeightTxtBox.BorderBrush = Brushes.Red;
                m_hasError = true;
            }

            if (m_hasError)
            {
                MessageBox.Show("Existem erros nos dados, por favor corrija.", "Aviso", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else if (p.PatWaist > MainWindow.Def.MAXIMUM_WAIST || (MainWindow.CurrentPatient.PatGender == PersonPatient.Gender.Male && p.PatWaist < MainWindow.Def.MALE_MINIMUM_WAIST) ||
                            (MainWindow.CurrentPatient.PatGender == PersonPatient.Gender.Female && p.PatWaist < MainWindow.Def.FEMALE_MINIMUM_WAIST))
            {
                WaistTxtBox.BorderBrush = Brushes.Red;
                MessageBox.Show("Por favor corriga o perímetro da cintura em centímetros", "Aviso", MessageBoxButton.OK, MessageBoxImage.Warning);
                m_hasError = true;
            }

            DoCalculations();

            return m_hasError;
        }

        /// <summary>
        /// Handle Name text change
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">TextChangedEventArgs</param>
        private void NameTxtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if ((TextBox)sender != null && MainWindow.CurrentPatient != null)
            {
                (sender as TextBox).BorderBrush = new SolidColorBrush(Color.FromArgb(255, 171, 173, 179));

                string name = ((TextBox)sender).Text;
                if (!string.IsNullOrEmpty(name))
                {
                    if (MainWindow.CurrentPatient.PatName != null)
                    {
                        if (!MainWindow.CurrentPatient.PatName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            MainWindow.CurrentPatient.PatName = name;
                        }
                    }
                    else
                    {
                        MainWindow.CurrentPatient.PatName = name;
                    }
                }
                else
                {
                    (sender as TextBox).BorderBrush = Brushes.Red;
                }

                HasChanges = true;
            }
        }

        /// <summary>
        /// Handle Year Of Birth change
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">SelectionChangedEventArgs</param>
        private void YOBCBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem item = YOBCBox.SelectedValue as ComboBoxItem;
            if (item != null && item.Content != null)
            {
                YOBCBox.Foreground = Brushes.Black;

                int value = 0;
                int.TryParse(item.Content.ToString(), out value);

                if (MainWindow.CurrentPatient != null && MainWindow.CurrentPatient.PatBirthYear != value)
                {
                    if ((FoodFormulas.CalculateAge(value) >= (int)MainWindow.Def.FOOD_MINIMUM_AGE))
                    {
                        MainWindow.CurrentPatient.PatBirthYear = value;
                    }
                }
            }
        }

        /// <summary>
        /// Handle Male button check
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void MaleRBtn_CheckedChanged(object sender, RoutedEventArgs e)
        {
            if (e != null && (RadioButton)e.Source != null && ((RadioButton)e.Source).IsChecked == true)
            {
                if (MainWindow.CurrentPatient != null && MainWindow.CurrentPatient.PatGender != PersonPatient.Gender.Male)
                {
                    MainWindow.CurrentPatient.PatGender = PersonPatient.Gender.Male;
                    RatingStarValues.SetMaxValue = StarValues.MAX_STARS;

                    MainWindow.CurrentPatient.PatPregnant =
                        MainWindow.CurrentPatient.PatFeeding = false;

                    PregantRBtn.IsEnabled =
                        FeedingRBtn.IsEnabled = false;

                    PregantRBtn.IsChecked =
                        FeedingRBtn.IsChecked = false;

                    HasChanges = true;
                }
            }
        }

        /// <summary>
        /// Handle Female button check
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FemaleRBtn_CheckedChange(object sender, RoutedEventArgs e)
        {
            if (e != null && (RadioButton)e.Source != null && ((RadioButton)e.Source).IsChecked == true)
            {
                if (sender as RadioButton != null && MainWindow.CurrentPatient != null)
                {
                    MainWindow.CurrentPatient.PatGender = PersonPatient.Gender.Female;

                    PregantRBtn.IsEnabled =
                        FeedingRBtn.IsEnabled = true;

                    PregantRBtn.IsChecked =
                        FeedingRBtn.IsChecked = false;

                    HasChanges = true;
                }
            }
        }

        /// <summary>
        /// Handle star rating
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">System.Windows.Input.MouseEventArgs</param>
        private void RatingStarValues_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if ((sender as StarValues) != null && MainWindow.CurrentPatient != null)
            {
                int value = (sender as StarValues).CurrentValue;
                DefaultValues.PatStarRatingValues currentValue = (DefaultValues.PatStarRatingValues)Enum.ToObject(typeof(DefaultValues.PatStarRatingValues), value);

                if (MainWindow.CurrentPatient.PatStarRating != currentValue)
                {
                    MainWindow.CurrentPatient.PatStarRating = currentValue;
                    HasChanges = true;
                }
            }
        }

        /// <summary>
        /// Handle the height value change
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">TextChangedEventArgs</param>
        private void HeightTxtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (MainWindow.CurrentPatient != null && (sender as TextBox) != null)
            {
                (sender as TextBox).BorderBrush = new SolidColorBrush(Color.FromArgb(255, 171, 173, 179));

                try
                {
                    double val = Convert.ToDouble((sender as TextBox).Text);
                    if (val < (double)MainWindow.Def.MINIMUM_HEIGHT)
                    {
                    }
                    if (!MainWindow.CurrentPatient.PatHeight.ToString().Equals((sender as TextBox).Text, StringComparison.InvariantCultureIgnoreCase))
                    {
                        MainWindow.CurrentPatient.PatHeight = val;
                        HasChanges = true;
                    }
                }
                catch (Exception)
                {
                    (sender as TextBox).BorderBrush = Brushes.Red;
                }
            }
        }

        /// <summary>
        /// Handle the weight value changes
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">TextChangedEventArgs</param>
        private void WeightTxtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (MainWindow.CurrentPatient != null && (sender as TextBox) != null)
            {
                (sender as TextBox).BorderBrush = new SolidColorBrush(Color.FromArgb(255, 171, 173, 179));

                try
                {
                    Double val = Convert.ToDouble((sender as TextBox).Text);
                    if (!MainWindow.CurrentPatient.PatWeight.ToString().Equals((sender as TextBox).Text, StringComparison.InvariantCultureIgnoreCase))
                    {
                        MainWindow.CurrentPatient.PatWeight = Convert.ToDouble((sender as TextBox).Text);
                        HasChanges = true;
                    }
                }
                catch (Exception)
                {
                    (sender as TextBox).BorderBrush = Brushes.Red;
                }
            }
        }

        private void WaistTxtBox_LostFocus(object sender, RoutedEventArgs e)
        {
            HasError();
        }

        /// <summary>
        /// Hanlde the waist value change.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">TextChangedEventArgs</param>
        private void WaistTxtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (MainWindow.CurrentPatient != null && (sender as TextBox) != null)
            {
                (sender as TextBox).BorderBrush = new SolidColorBrush(Color.FromArgb(255, 171, 173, 179));

                try
                {
                    Double val = Convert.ToDouble((sender as TextBox).Text);
                    if (!MainWindow.CurrentPatient.PatWaist.ToString().Equals((sender as TextBox).Text, StringComparison.InvariantCultureIgnoreCase))
                    {
                        MainWindow.CurrentPatient.PatWaist = val;
                        HasChanges = true;
                    }
                }
                catch (Exception)
                {
                    (sender as TextBox).BorderBrush = Brushes.Red;
                }
            }
        }

        /// <summary>
        /// Handles the Preganant check
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void PregantRBtn_CheckedChanged(object sender, RoutedEventArgs e)
        {
            if (sender != null)
            {
                bool? result = ((CheckBox)sender).IsChecked;

                if (MainWindow.CurrentPatient != null && MainWindow.CurrentPatient.PatPregnant != result)
                {
                    MainWindow.CurrentPatient.PatPregnant = result;

                    if (result == true)
                    {
                        RatingStarValues.SetMaxValue = 2;
                        if (MainWindow.CurrentPatient.PatFeeding == true)
                        {
                            FeedingRBtn.IsChecked = false;
                        }
                    }
                    else if (PregantRBtn.IsChecked == false && FeedingRBtn.IsChecked == false)
                    {
                        RatingStarValues.SetMaxValue = StarValues.MAX_STARS;
                    }

                    HasChanges = true;
                }
            }
        }

        /// <summary>
        /// Hanlde the Feeding check button
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void FeedingRBtn_CheckedChanged(object sender, RoutedEventArgs e)
        {
            if (sender != null)
            {
                bool? result = ((CheckBox)sender).IsChecked;

                if (MainWindow.CurrentPatient != null && MainWindow.CurrentPatient.PatFeeding != result)
                {
                    MainWindow.CurrentPatient.PatFeeding = result;

                    if (result == true)
                    {
                        RatingStarValues.SetMaxValue = 3;
                        if (MainWindow.CurrentPatient.PatPregnant == true)
                        {
                            PregantRBtn.IsChecked = false;
                        }
                    }
                    else if (PregantRBtn.IsChecked != true && FeedingRBtn.IsChecked != true)
                    {
                        RatingStarValues.SetMaxValue = StarValues.MAX_STARS;
                    }

                    HasChanges = true;
                }
            }
        }

        /// <summary>
        /// Handle the Observations text change
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">TextChangedEventArgs</param>
        private void ObsTxtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (MainWindow.CurrentPatient != null && (sender as TextBox) != null)
            {
                MainWindow.CurrentPatient.PatObs = (sender as TextBox).Text;
                HasChanges = true;
            }
            
        }

        /// <summary>
        /// Handle the Add button click
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            if (MainWindow.CurrentPatient != null && HasChanges)
            {
                if (MessageBox.Show("Existem alterações, deseja continuar e perder as mesmas?", "Aviso", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }
            }

            MainWindow.CurrentPatient = new PersonPatient();        // New patient data, no previous data was loaded

            InitiValues();

            string date = DateTime.Now.ToString("dd-MM-yyyy");
            MainWindow.CurrentPatient.PatCreationDate = date;
            CreationDateLbl.Content = CREATION_DATE_TEXT + date;

            TopGrid.IsEnabled = true;

            HasChanges = true;

            if (LoadDataEvent != null)
            {
                LoadDataEvent(true);
            }
        }

        /// <summary>
        /// Handle the Delete button click
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            if (HasChanges)
            {
                if (MessageBox.Show("Existem alterações, deseja continuar e perder as mesmas?", "Aviso", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }
            }

            string warningMsg = "Tem a certeza que deseja apagar os dados para a pessoa " + NameTxtBox.Text;
            if (MessageBox.Show(warningMsg, "Aviso", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    string filename = MainWindow.ProfileDirectory + MainWindow.CurrentPatient.PatName + MainWindow.PERSON_DATA_FILE_EXTENSION;
                    System.IO.File.Delete(filename);
                    MessageBox.Show("Os dados foram apagados", "Aviso", MessageBoxButton.OK, MessageBoxImage.Information);

                    MainWindow.CurrentPatient = null;

                    InitiValues();
                    DoCalculations();

                    if (LoadDataEvent != null)
                    {
                        LoadDataEvent(true);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Não foi possível apagar os dados", "Aviso", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }

        /// <summary>
        /// Handle the Edit button click
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void EditBtn_Click(object sender, RoutedEventArgs e)
        {
            if (MainWindow.CurrentPatient != null)
            {
                TopGrid.IsEnabled = true;
            }
        }

        /// <summary>
        /// Handle the save button click. Check for errors and save current data.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            if (HasError())
            {
                return;
            }

            try
            {
                MainWindow.CurrentPatient.SaveBiometricData();

                string filename = MainWindow.ProfileDirectory + MainWindow.CurrentPatient.PatName + MainWindow.PERSON_DATA_FILE_EXTENSION;

                if (MainHelper.SerializePersonObject(filename, MainWindow.CurrentPatient))
                {
                    MessageBox.Show("Dados gravados com sucesso.", "Aviso", MessageBoxButton.OK, MessageBoxImage.Information);

                    EvolutionBtn.IsEnabled =
                        DeleteBtn.IsEnabled = true;
                        
                    HasChanges = false;

                    TopGrid.IsEnabled =
                        SaveBtn.IsEnabled = false;

                    if (LoadDataEvent != null)
                    {
                        LoadDataEvent(true);
                    }

                    DoCalculations();

                    return;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Ex: " + ex.Message);
            }

            MessageBox.Show("Não foi possível gravar.\nPor favor tente outra vez.", "Aviso", MessageBoxButton.OK, MessageBoxImage.Error);
        }

        /// <summary>
        /// Handle the Open button click. Displays a file browse and imports PersonPatient data.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void OpenBtn_Click(object sender, RoutedEventArgs e)
        {
            LoadLocalFileListPopUp lplpu = new LoadLocalFileListPopUp(MainWindow.ProfileDirectory, MainWindow.PERSON_DATA_FILE_EXTENSION, null);
            lplpu.SetInstructions("Escolha a Ficha Pessoal da lista abaixo:");
            lplpu.Owner = Application.Current.MainWindow;
            lplpu.ShowDialog();
            m_CurrentPersonFile = lplpu.getSelectedItem();

            if (!string.IsNullOrEmpty(m_CurrentPersonFile))
            {
                PersonPatient person = (PersonPatient)MainHelper.DeSerializePersonObject(MainWindow.ProfileDirectory + m_CurrentPersonFile + MainWindow.PERSON_DATA_FILE_EXTENSION);

                if (person != null && FillPersonData(person))
                {
                    TopGrid.IsEnabled =
                        HasChanges = false;

                    EvolutionBtn.IsEnabled =
                        DeleteBtn.IsEnabled =
                        EditBtn.IsEnabled = true;

                    if (LoadDataEvent != null)
                    {
                        LoadDataEvent(true);
                    }

                    DoCalculations();

                    return;
                }
                else
                {
                    MessageBox.Show("Não foi possível carregar os dados.", "Aviso", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }

        /// <summary>
        /// Call for patient data calculations
        /// </summary>
        private void DoCalculations()
        {
            CheckIMC();
            CheckPC();
        }

        /// <summary>
        /// Loads given person data into screen and returns a boolean result
        /// </summary>
        /// <param name="person">PersonPatient</param>
        /// <returns>bool</returns>
        private bool FillPersonData(PersonPatient person)
        {
            try
            {
                MainWindow.CurrentPatient = person;

                CreationDateLbl.Content = CREATION_DATE_TEXT + person.PatCreationDate;
                NameTxtBox.Text = person.PatName;
                YOBCBox.Text = person.PatBirthYear.ToString();
                MaleRBtn.IsChecked = (person.PatGender == PersonPatient.Gender.Male) ? true : false;
                FemaleRBtn.IsChecked = (person.PatGender == PersonPatient.Gender.Female) ? true : false;
                PregantRBtn.IsChecked = (bool)person.PatPregnant;
                PregantRBtn.IsEnabled = (person.PatGender == PersonPatient.Gender.Female) ? true : false;
                FeedingRBtn.IsChecked = (bool)person.PatFeeding;
                FeedingRBtn.IsEnabled = (person.PatGender == PersonPatient.Gender.Female) ? true : false;
                ObsTxtBox.Text = person.PatObs;
                HeightTxtBox.Text = person.PatHeight.ToString("F0");
                WeightTxtBox.Text = person.PatWeight.ToString("F0");
                WaistTxtBox.Text = person.PatWaist.ToString("F0");

                RatingStarValues.SetStarValues(person.PatStarRating);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// Check the person«s PC value.
        /// </summary>
        private void CheckPC()
        {
            if (MainWindow.CurrentPatient != null)
            {
                DefaultValues.PCValues pcValue = FoodFormulas.CalculatePC(MainWindow.CurrentPatient);
                MainWindow.CurrentPatient.PatPC = pcValue;
                PCTxtBox.Text = MainHelper.GetEnumDescription((Enum)pcValue);
            }
        }

        /// <summary>
        /// Calculate the person's IMC according to new values.
        /// </summary>
        private void CheckIMC()
        {
            if (MainWindow.CurrentPatient != null)
            {
                if (MainWindow.CurrentPatient.PatHeight != 0 && MainWindow.CurrentPatient.PatWeight != 0)
                {
                    Double value = FoodFormulas.CalculateIMC(MainWindow.CurrentPatient);
                    MainWindow.CurrentPatient.PatIMC = value;

                    IMCClassTxtBox.Text = FoodFormulas.GetIMCClassification(value);
                    IMCTxtBox.Text = value.ToString("F2");
                }
                else
                {
                    MainWindow.CurrentPatient.PatIMC = 0;
                    IMCTxtBox.Text = "";
                }
            }
        }

        /// <summary>
        /// Hanldes the evolution button click
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void EvolutionBtn_Click(object sender, RoutedEventArgs e)
        {
            EvolutionPopup epu = new EvolutionPopup();
            epu.Owner = Application.Current.MainWindow;
            epu.ShowDialog();
        }
    }
}
